{extend name="Public:content"}
{block name="button"}
<!--工具栏 start-->
<div id="toolbar" class="row">
    <div class="col-sm-12 m-b-xs">
        <button type="button" class="btn-sm btn-success" onclick="wechat_news.add()">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>添加图文
        </button>
        <button type="button" class="btn-sm btn-danger" onclick="wechat_news.batch_del()">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除图文
        </button>
    </div>
</div>
<!--工具栏 end-->
{/block}
{block name="content"}
<div class="table-responsive" style="overflow-x:initial">
    <table id="table" ></table>
</div>
{/block}
{block name="script"}
<script src="__STATIC__/admin/plugins/table-export/tableExport.min.js"></script>
<script src="__STATIC__/admin/plugins/bootstrap-table/extensions/export/bootstrap-table-export.min.js"></script>
<script type="text/javascript">
    $("input[class='form-control']").keypress(function (e) {
        var e = e || window.event;
        if (e.keyCode == 13) {
            $(".btn.btn-info").click();
        }
    });
    window.wechat_news = {
        //定义工具栏
        add: function(){ //添加
            parent.layer.open({
                type: 2,
                title: '{$title} > 添加',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("admin/wechatNews/add")}?iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        edit: function(id){ //编辑
            parent.layer.open({
                type: 2,
                title: '{$title} > 编辑',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("admin/wechatNews/edit")}?id='+id+'&iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        //批量删除操作
        batch_del: function(){
            var ids = $.map($("#table").bootstrapTable('getSelections'),function(row){
                return row.id;
            })
            if(ids.length == 0){
                layer.msg("请先选择要删除的记录!");
                return false;
            }
            layer.confirm('确认要删除吗？',function(){
                $.post('{:url("admin/wechatNews/del")}',{'id':ids,'field':'delete'},function(data){
                    if(200 == data.code){
                        //删除该行
                        $("#table").bootstrapTable('remove',{field:'id',values:ids});
                    }
                    layer.msg(data.msg);
                })
            })
        },
        push: function(id){ //详情
            parent.layer.open({
                type: 2,
                title: '{$title} > 推送',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("admin/wechatNews/push")}?id='+id+'&iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        review:function(content,type){ //预览
            parent.layer.open({
                type: 2,
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['317px', '580px'],
                content: '{:url("admin/wechat/review")}?content='+content+'&type='+type+'&iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },

        //操作格式化
        opert: function(value,row){
            var rst = '';
            var edit_auth = '{:auth("$classuri/edit")}';
            var push_auth = '{:auth("$classuri/push")}';
            var del_auth = '{:auth("$classuri/del")}';
            if(edit_auth) {
                rst += '<a onclick="wechat_news.edit('+row.id+')" class="btn btn-outline btn-default btn-xs">编辑</a> ';
            }
            if(push_auth) {
                rst += '<a onclick="wechat_news.push('+row.id+')" class="btn btn-outline btn-warning btn-xs">推送</a> ';
            }
            if(del_auth) {
                rst += '<a onClick="$.Oa.delete(this,false,false)" data-href="{:url(\'admin/wechatNews/del\')}" data-id="'+row.id+'" class="btn btn-outline btn-danger btn-xs">删除</a> ';
            }
            return rst;
        }
    }
    $('#table').bootstrapTable({
        toolbar: "#toolbar",
        search:true,
        showColumns: true,
        showRefresh: false,
        showExport: true,                     //是否显示导出
        exportDataType: "basic",              //basic', 'all', 'selected'.

        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        url:"{:url(\"admin/wechatNews/index\")}",
        pageNumber: 1, //初始化加载第一页，默认第一页
        pagination:true,//是否分页
        sortOrder: 'desc',
        sidePagination:'server',//指定服务器端分页
        queryParamsType : "",
        queryParams: function(params){
            return {limit:params.pageSize,page:params.pageNumber,order:params.sortOrder};
        },//参数
        pageSize:10,//单页记录数
        pageList:[10,20,30,40],//分页步进值
        // responseHandler:responseHandler,//请求数据成功后，渲染表格前的方法
        columns :[
            {checkbox:true,width: 20},
            {field:'id',title:'ID',width: 20},
            {field:'articles.0.local_url',title:'图片',width: 80,formatter:function(value){
                return '<img src="'+value+'" style="max-width:80px; height: 40px;"/>';
            }},
            {field:'articles.0.title',title:'标题',width: 80},
            {field:'articles.0.author',title:'作者',width: 80},
            {field:'articles.0.content_source_url',title:'原文链接',width: 80,formatter:function(value){
                return value ? '<a onclick="$.Oa.copayUrl(\''+value+'\')" class="label label-primary" >复制</a>' : '暂无';
            }},
            {field:'content',title:'预览',width: 80,formatter:function(value,row){
                return '<a onclick="wechat_news.review('+row.id+',\'news\')" class="label label-primary" >预览</a>';
            }},
            {field:'create_at',title:'更新时间',width: 80},
            {field:'action',title:'操作',width: 80,formatter:wechat_news.opert},
        ]
    })
</script>
{/block}